﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AiXiu.BLL;
using AiXiu.Model;
using AiXiu.DAL;
using AiXiu.Common;
using System.Web.UI.WebControls;

namespace AiXiu.BLL
{
 public   class LoginBLL
    {
        AiXiuDbContext db = new AiXiuDbContext();
        public OperResult<TBUsers> Login(string UserName,string Password,int id) {
            //非空验证
            if (string.IsNullOrEmpty(UserName)||string.IsNullOrEmpty(Password)) {
                return OperResult<TBUsers>.Failed("用户名和密码不能为空");
            }
            //通过用户名查询用户，不存在返回错误信息
            LoginDAL LoginDAL = new LoginDAL();
            TBLogins tb = LoginDAL.ExixtsName(UserName);
            if (tb==null)
            {
                return OperResult<TBUsers>.Failed("用户名错误");
            }
            //验证加密
            SHAEncryption sha = new SHAEncryption();
            string en = sha.SHA1Encrypt(Password);
            if (tb.Password!=en)
            {
                return OperResult<TBUsers>.Failed("密码错误");
            }
            TBUsers user = LoginDAL.inquire(tb.Id);
            return OperResult<TBUsers>.Succeed(user);
        }  
    }
}
